package com.xuanxing123.model;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import javax.persistence.*;
import static javax.persistence.GenerationType.IDENTITY;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name="product",catalog="xuanxing")
@Searchable
@XmlRootElement
public class Product extends BaseObject implements Serializable {
    private Long id;
    private Integer version;
    private ProductType productType;
    private Brand brand;
    private String name;
    private String image;
    private String description;
    private String comments;
    private String website;
    private String phone;
    private String numberOfCustomer;
    private Integer structure;
    private Integer marketPositioning;
    private Integer implCycle;
    private Integer totalBudget;
    private Integer priceAdvantage;
    private Integer numberOfUsers;
    private Integer rate;
    private Integer position;
    private Boolean enabled;
    private List<ProductModule> productModules = new ArrayList<ProductModule>(0);
    private List<ProductIndustry> productIndustries = new ArrayList<ProductIndustry>(0);

    @Id @GeneratedValue(strategy=IDENTITY)
    @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="version")
    @SearchableProperty
    public Integer getVersion() {
        return this.version;
    }
    
    public void setVersion(Integer version) {
        this.version = version;
    }

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="type_id", nullable=false)
    public ProductType getProductType() {
        return this.productType;
    }
    
    public void setProductType(ProductType productType) {
        this.productType = productType;
    }
    
    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="brand_id", nullable=false)
    public Brand getBrand() {
        return this.brand;
    }
    
    public void setBrand(Brand brand) {
        this.brand = brand;
    }
    
    @Column(name="name", nullable=false, length=100)
    @SearchableProperty
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="image", length=254)
    @SearchableProperty
    public String getImage() {
        return this.image;
    }
    
    public void setImage(String image) {
        this.image = image;
    }
    
    @Column(name="description", length=254)
    @SearchableProperty
    public String getDescription() {
        return this.description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Column(name="comments", length=254)
    @SearchableProperty
    public String getComments() {
        return this.comments;
    }
    
    public void setComments(String comments) {
        this.comments = comments;
    }
    
    @Column(name="website", length=100)
    @SearchableProperty
    public String getWebsite() {
        return this.website;
    }
    
    public void setWebsite(String website) {
        this.website = website;
    }
    
    @Column(name="phone", length=50)
    @SearchableProperty
    public String getPhone() {
        return this.phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    @Column(name="number_of_customer", length=50)
    @SearchableProperty
    public String getNumberOfCustomer() {
        return this.numberOfCustomer;
    }
    
    public void setNumberOfCustomer(String numberOfCustomer) {
        this.numberOfCustomer = numberOfCustomer;
    }
    
    @Column(name="structure", nullable=false)
    @SearchableProperty
    public Integer getStructure() {
        return this.structure;
    }
    
    public void setStructure(Integer structure) {
        this.structure = structure;
    }
    
    @Column(name="market_positioning", nullable=false)
    @SearchableProperty
    public Integer getMarketPositioning() {
        return this.marketPositioning;
    }
    
    public void setMarketPositioning(Integer marketPositioning) {
        this.marketPositioning = marketPositioning;
    }
    
    @Column(name="impl_cycle", nullable=false)
    @SearchableProperty
    public Integer getImplCycle() {
        return this.implCycle;
    }
    
    public void setImplCycle(Integer implCycle) {
        this.implCycle = implCycle;
    }
    
    @Column(name="total_budget", nullable=false)
    @SearchableProperty
    public Integer getTotalBudget() {
        return this.totalBudget;
    }
    
    public void setTotalBudget(Integer totalBudget) {
        this.totalBudget = totalBudget;
    }

    @Column(name="price_advantage", nullable=false)
    @SearchableProperty
    public Integer getPriceAdvantage() {
        return priceAdvantage;
    }

    public void setPriceAdvantage(Integer priceAdvantage) {
        this.priceAdvantage = priceAdvantage;
    }

    @Column(name="number_of_users", nullable=false)
    @SearchableProperty
    public Integer getNumberOfUsers() {
        return this.numberOfUsers;
    }
    
    public void setNumberOfUsers(Integer numberOfUsers) {
        this.numberOfUsers = numberOfUsers;
    }
    
    @Column(name="rate", nullable=false)
    @SearchableProperty
    public Integer getRate() {
        return this.rate;
    }
    
    public void setRate(Integer rate) {
        this.rate = rate;
    }
    
    @Column(name="position", nullable=false)
    @SearchableProperty
    public Integer getPosition() {
        return this.position;
    }
    
    public void setPosition(Integer position) {
        this.position = position;
    }
    
    @Column(name="enabled")
    @SearchableProperty
    public Boolean getEnabled() {
        return this.enabled;
    }
    
    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="product")
    public List<ProductModule> getProductModules() {
        return this.productModules;
    }
    
    public void setProductModules(List<ProductModule> productModules) {
        this.productModules = productModules;
    }

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="product")
    public List<ProductIndustry> getProductIndustries() {
        return this.productIndustries;
    }
    
    public void setProductIndustries(List<ProductIndustry> productIndustries) {
        this.productIndustries = productIndustries;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Product pojo = (Product) o;

        if (version != null ? !version.equals(pojo.version) : pojo.version != null) return false;
        if (productType != null ? !productType.equals(pojo.productType) : pojo.productType != null) return false;
        if (brand != null ? !brand.equals(pojo.brand) : pojo.brand != null) return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (image != null ? !image.equals(pojo.image) : pojo.image != null) return false;
        if (description != null ? !description.equals(pojo.description) : pojo.description != null) return false;
        if (comments != null ? !comments.equals(pojo.comments) : pojo.comments != null) return false;
        if (website != null ? !website.equals(pojo.website) : pojo.website != null) return false;
        if (phone != null ? !phone.equals(pojo.phone) : pojo.phone != null) return false;
        if (numberOfCustomer != null ? !numberOfCustomer.equals(pojo.numberOfCustomer) : pojo.numberOfCustomer != null) return false;
        if (structure != null ? !structure.equals(pojo.structure) : pojo.structure != null) return false;
        if (marketPositioning != null ? !marketPositioning.equals(pojo.marketPositioning) : pojo.marketPositioning != null) return false;
        if (implCycle != null ? !implCycle.equals(pojo.implCycle) : pojo.implCycle != null) return false;
        if (totalBudget != null ? !totalBudget.equals(pojo.totalBudget) : pojo.totalBudget != null) return false;
        if (numberOfUsers != null ? !numberOfUsers.equals(pojo.numberOfUsers) : pojo.numberOfUsers != null) return false;
        if (rate != null ? !rate.equals(pojo.rate) : pojo.rate != null) return false;
        if (position != null ? !position.equals(pojo.position) : pojo.position != null) return false;
        if (enabled != null ? !enabled.equals(pojo.enabled) : pojo.enabled != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (version != null ? version.hashCode() : 0);
        result = 31 * result + (productType != null ? productType.hashCode() : 0);
        result = 31 * result + (brand != null ? brand.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (image != null ? image.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (comments != null ? comments.hashCode() : 0);
        result = 31 * result + (website != null ? website.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (numberOfCustomer != null ? numberOfCustomer.hashCode() : 0);
        result = 31 * result + (structure != null ? structure.hashCode() : 0);
        result = 31 * result + (marketPositioning != null ? marketPositioning.hashCode() : 0);
        result = 31 * result + (implCycle != null ? implCycle.hashCode() : 0);
        result = 31 * result + (totalBudget != null ? totalBudget.hashCode() : 0);
        result = 31 * result + (numberOfUsers != null ? numberOfUsers.hashCode() : 0);
        result = 31 * result + (rate != null ? rate.hashCode() : 0);
        result = 31 * result + (position != null ? position.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("version").append("='").append(getVersion()).append("', ");
        sb.append("productType").append("='").append(getProductType()).append("', ");
        sb.append("brand").append("='").append(getBrand()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("image").append("='").append(getImage()).append("', ");
        sb.append("description").append("='").append(getDescription()).append("', ");
        sb.append("comments").append("='").append(getComments()).append("', ");
        sb.append("website").append("='").append(getWebsite()).append("', ");
        sb.append("phone").append("='").append(getPhone()).append("', ");
        sb.append("numberOfCustomer").append("='").append(getNumberOfCustomer()).append("', ");
        sb.append("structure").append("='").append(getStructure()).append("', ");
        sb.append("marketPositioning").append("='").append(getMarketPositioning()).append("', ");
        sb.append("implCycle").append("='").append(getImplCycle()).append("', ");
        sb.append("totalBudget").append("='").append(getTotalBudget()).append("', ");
        sb.append("numberOfUsers").append("='").append(getNumberOfUsers()).append("', ");
        sb.append("rate").append("='").append(getRate()).append("', ");
        sb.append("position").append("='").append(getPosition()).append("', ");
        sb.append("enabled").append("='").append(getEnabled()).append("', ");
        
        
        sb.append("]");
      
        return sb.toString();
    }

}
